﻿using Gx.Common;
using Gx.Common.Core;
using Gx.Dal.Manage;
using Gx.Model;
using Gx.Model.Entity;
using Gx.Model.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;


namespace Gx.Bll.Manage
{
    public class LKCompanyBll
    {
    
        protected LKCompanyDal dal = new LKCompanyDal();
    
        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public PagedList<LKCompany> GetLKCompanyPageList(LKCompanyInput input)
        {
            return dal.GetLKCompanyPageList(input);
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        public List<LKCompany> GetLKCompanys()
        {
            return dal.GetAll().ToList();
        }

        /// <summary>
        /// 新增公司表
        /// </summary>
        /// <param name="lKCompany"></param>
        /// <returns></returns>
        public ReturnModel AddLKCompany(LKCompany lKCompany)
        {

            var any = dal.AnyName(lKCompany.CompanyName);
            if (any)
            {
                return new ReturnModel { Success = false, Msg = "名称已存在" };
            }


            lKCompany.CreateTime = DateTime.Now;
            lKCompany.CreateUserId = LoginHelper.GetUserId();
            lKCompany.CreateUser = LoginHelper.UserName();
            var result= dal.Insert(lKCompany);
            return new ReturnModel { Success = result, Msg = result ? "新增成功" : "新增失败" };
        }

        /// <summary>
        /// 编辑公司表
        /// </summary>
        /// <param name="lKCompany"></param>
        /// <returns></returns>
        public bool EditLKCompany(LKCompany lKCompany)
        {
            var cus = dal.Get(lKCompany.Id);
            if (cus == null)
            {
                return false;
            }
            lKCompany.CreateTime = cus.CreateTime;
            lKCompany.CreateUserId = cus.CreateUserId;
            lKCompany.CreateUser = cus.CreateUser;
            return dal.Update(lKCompany);
        }

        /// <summary>
        /// 删除公司表
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteLKCompany(int id)
        {
            return dal.DeleteById(id);
        }

        /// <summary>
        /// 编辑公司表
        /// </summary>
        /// <param name="lKCompany"></param>
        /// <returns></returns>
        public LKCompany GetLKCompany(int id)
        {
            var cus = dal.Get(id);
            return cus;
        }
    }
}

